	/* 
	 * JTable solicitudes
	 */
	$(document).ready(function() {              
	    //setup the jtable that will display the results
	    $('#TablaListaSolicitudes').jtable({
	        title: ' ',
	        selecting: true, //Enable selecting 
	        paging: true, //Enable paging
	        pageSize: 10, //Set page size (default: 10)
	        sorting: true, //Enable sorting
            defaultSorting: 'Solicitudid ASC', //Set default sorting
	        actions: {
	        	listAction: 'getSolicitudes',
	        },
	        fields: {
	        	Solicitudid: {
	                title: 'ID',
	                width: '5%',
	                inputClass : 'validate[required]',
	    	        sorting: true,
	            },
	        	Usuarioid: {
	        		key: true,
	                visibility: 'hidden',
	            },
            
	            Solicitud: {
                    title: 'Editar',
                    type: 'img',
                    create: false,
                    edit: false,
                    sorting: false,
                    list: true,
                    display: function(data){
                    		return '<a href="editar?id='+  data.record.Solicitudid + '" ><img Style="max-width: 100%;" src="/plantilla/images/sesiones.png" width="41" height="17" class="preview"></a>';
                    },
                    width: "5%"
                },
                Informe: {
                    title: 'Inf',
                    type: 'file',
                    create: false,
                    edit: false,
                    sorting: false,
                    list: true,
                    display: function(data){
                    	if (data.record.Situacionid==3||data.record.Situacionid==5){
                    		if ($('#empleado')!=undefined && data.record.Compartir==true){
                    			return '<a href="/private/informes/mostrar?solicitud='+  data.record.Solicitudid + '" ><img src="/plantilla/images/informefile_act.png" width="32" height="32" class="preview"></a>';
                    		}else if ($('#empleado').val()!=undefined && data.record.Compartir==false){
                    			return '<img src="/plantilla/images/informefile.png" width="32" height="32" class="preview">';
                    		}else{
                    			return '<a href="/private/informes/mostrar?solicitud='+  data.record.Solicitudid + '" ><img src="/plantilla/images/informefile_act.png" width="32" height="32" class="preview"></a>';
                    		}
                    	}else{
                    		return '<img src="/plantilla/images/informefile.png" width="32" height="32" class="preview">';
                    	}
                    },
                    width: "5%",
                    listClass: "class-row-center"
                },
	            Fechalta: {
	                title: 'F. Alta',
	                width: '10%',
	                sorting: false
	            },
	            Rutafichero: {
                    title: '',
                    edit:false,
                    list:false,
                    create: false,
                },	   
                Compartir: {
                    title: '',
                    edit:false,
                    list:false,
                    create: false,
                },	  
	            Dispositivo: {
	                title: 'Dispositivo',
	                width: '10%',
	                sorting: false
	            },
	            Empleado: {
	                title: 'Creador',
	                width: '20%',
	                sorting: false
	            },
	            Usuario: {
	                title: 'Usuario',
	                width: '20%',
	                sorting: false
	            },
	            Situacionid: {
	                title: 'Situación',
	                width: '10%',
	                sorting: true,
	                options: function(data){
	                	return 'sesiones/getTodosLosEstados'
	                },
	            },
	        },
	        
	      //Initialize validation logic when a form is created
            formCreated: function (event, data) {
                data.form.validationEngine();
            },
            //Validate form when it is being submitted
            formSubmitting: function (event, data) {
                return data.form.validationEngine('validate');
            },
            //Dispose validation logic when form is closed
            formClosed: function (event, data) {
                data.form.validationEngine('hide');
                data.form.validationEngine('detach');
            },
	        //Register to selectionChanged event to hanlde events                                     
	        recordAdded: function(event, data){
	            //after record insertion, reload the records
	            $('#TablaListaSolicitudes').jtable('load');
	        },
	        recordUpdated: function(event, data){
	            //after record updation, reload the records
	            $('#TablaListaSolicitudes').jtable('load');
	        }
	    });
	  //Re-load records when user click 'load records' button.
        $('#botonbuscar').click(function (e) {
            e.preventDefault();
            $('#TablaListaSolicitudes').jtable('load', {
                situacionid: $('#situacion').val(),
                fechades: $('#fechades').val(),
                fechahas: $('#fechahas').val(),
                usuarioid:$('#usuarioid').val()
            });
        });
 
        //Load all records when page is first shown
        $('#botonbuscar').click();              
	                
	});


	 /*createAction: function (postData) {
        console.log("creating from custom function...");
        var json = {"empleadoId":"prueba", "nombre": "nombrepruebe", "apellido": "apellidoprueba"}
        return $.Deferred(function ($dfd) {
            $.ajax({
                url:  $("#contextPath").val()+"/private/control/solicitudes/addEmpleado",
                type: 'POST',
                dataType: 'json',
                data: JSON.stringify(json),
                success: function (data) {
                    $dfd.resolve(data);
                },
                error: function () {
                    $dfd.reject();
                }
            });
        });
    },*/